﻿using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;

namespace VASJ.Model
{
    public class OrganizationManager : DataContextOwner
    {
        public OrganizationManager()
        {
        }

        public OrganizationManager(KeToanDataContext dataContext)
            : base(dataContext)
        {
        }

        //public string GetSavePath()
        //{
        //    string path = System.Configuration.ConfigurationManager.AppSettings["DocumentPath"];
        //    path = path.Trim(@"\/".ToCharArray());
        //    return HostingEnvironment.MapPath(path);
        //}

        public IEnumerable<Organization> GetList()
        {
            Table<Organization> OrganizationTable = m_DataContext.Organizations;

            var OrganizationList = from d in OrganizationTable select d;

            return OrganizationList;
        }

        public Organization GetOrganization(string id)
        {
            var OrganizationTable = m_DataContext.Organizations;

            Organization Organization = (from p in OrganizationTable where p.Id.Equals(id) select p).FirstOrDefault();

            return Organization;
        }

        public void Add(Organization Organization)
        {
            m_DataContext.Organizations.InsertOnSubmit(Organization);
            m_DataContext.SubmitChanges();
        }

        public void Edit(Organization Organization)
        {
            var editOrganization = GetOrganization(Organization.Id);

            if (editOrganization != null)
            {
                m_DataContext.SubmitChanges();
            }
        }
    }
}
